package com.itany.cloud.service.impl;

import com.itany.cloud.entity.Dept;
import com.itany.cloud.entity.Emp;
import com.itany.cloud.mapper.DeptMapper;
import com.itany.cloud.service.DeptService;
import com.itany.cloud.service.EmpServiceClient;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 石小俊
 */
@Service
public class DeptServiceImpl implements DeptService {

    @Autowired(required = false)
    private DeptMapper deptMapper;

    @Autowired
    private EmpServiceClient empServiceClient;

    @GlobalTransactional
    @Override
    public void addDept(Dept dept) {
        deptMapper.insert(dept);
        // 添加部门的同时添加一个员工
        Emp emp = new Emp();
        emp.setName("admin");
        emp.setDeptId(dept.getId());
        empServiceClient.addEmp(emp);
    }
}
